<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <title>Weblogic管理</title>
    <link rel="icon" href="">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
    <style type="text/css">
    	#create_domain_link{
    		float: right;
		    text-decoration: underline;
		    color: #337ab7;
    	}
    </style>
  </head>
  <body>

  	<div class="panel panel-default">
	  <div class="panel-heading">
	    <h3 class="panel-title">域列表 <a id="create_domain_link" href="#">创建域</a></h3>
	  </div>
	  <div class="panel-body" id="domain_list">
	  	
	  </div>
	</div>

	<script id="domain-list" type="text/html">
		<ul>
			{{each data item}}
	  		<li>{{item}} <a href="#" class="domains-start-link" data-domainid="{{item}}">启动</a></li>
	  		{{/each}}
	  	</ul>
	</script>

  	<script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../js/template-web.js"></script>
    <script type="text/javascript">

    	var domainDir="/home/self/apps/Oracle/Middleware/Oracle_Home/user_projects/domains";
    	$("body").on("click","a.domains-start-link",function(){
    		var domainId=$(this).data("domainid");
    		var startCmd=`gnome-terminal -e "sh ${domainDir}/${domainId}/bin/startWebLogic.sh"`;
    		window.top.app.run(startCmd);
    	});

    	var loadWeblogicDomainList=function(){
    		var domains=[];
    		var fs=require('fs');
    		var files = fs.readdirSync(domainDir);
    		files.forEach(function(item,index){
    			var stat = fs.lstatSync(domainDir+"/"+item);
    			if(stat.isDirectory()==true
    				&&fs.existsSync(domainDir+'/'+item+'/bin/startWebLogic.sh')){
    				domains.push(item);
    			}
    		});

    		$("#domain_list").html(template("domain-list",{data:domains}));
    	};

    	loadWeblogicDomainList();

    	$("#create_domain_link").click(function(){
    		var cmd="sh /home/self/apps/Oracle/Middleware/Oracle_Home/wlserver/common/bin/config.sh";
    		window.top.app.run(cmd);
    	});
    </script>
  </body>
</html>
